import {
  BaseEntity,
  CreateDateColumn,
  UpdateDateColumn,
  DeleteDateColumn,
  BeforeInsert,
  PrimaryColumn,
  AfterLoad,
} from 'typeorm';
import * as uuidv4 from 'uuid';
export class PublicEntity extends BaseEntity {
  @PrimaryColumn({
    type: 'varchar',
    length: 50,
    nullable: false,
    name: 'id',
    comment: '主键ID',
  })
  id: string | null;

  @CreateDateColumn({
    type: 'timestamp',
    nullable: false,
    name: 'created_at',
    comment: '创建时间',
  })
  createdAt: Date | number;

  @UpdateDateColumn({
    type: 'timestamp',
    nullable: false,
    name: 'updated_at',
    comment: '更新时间',
  })
  updatedAt: Date;

  @DeleteDateColumn({
    type: 'timestamp',
    nullable: false,
    name: 'deleted_at',
    select: false,
    comment: '软删除时间',
  })
  deletedAt: Date;

  @BeforeInsert()
  formatId() {
    this.id = uuidv4.v4().replace(/-/g, '');
  }
}
